//
//  EmptyTableViewCell.m
//  DanaKreditLoan
//
//  Created by ZhengChengFeng on 2024/10/20.
//

#import "EmptyTableViewCell.h"

@implementation EmptyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        UIImage *img = [UIImage imageNamed:@"icon_empty"];
        
        self.iconV = [[UIImageView alloc] init];
        [self.contentView addSubview:self.iconV];
        [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@((kScreenWidth - img.size.width)/2));
            make.width.equalTo(@(img.size.width));
            make.height.equalTo(@(img.size.height));
            make.top.equalTo(self.contentView.mas_top).offset(140);
        }];
        
    
        self.btn = [[UIButton alloc] init];
        self.btn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:14];
        [self.btn setTitleColor:kButtonDefaultColor forState:UIControlStateNormal];
        [self.btn setTitleColor:kButtonDefaultColor forState:UIControlStateSelected];
        [self.btn setTitleColor:kButtonDefaultColor forState:UIControlStateHighlighted];
        [self.contentView addSubview:self.btn];
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@((kScreenWidth - 110)/2));
            make.width.equalTo(@110);
            make.height.equalTo(@36);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
        }];
        [self.btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
        self.btn.layer.cornerRadius = 18;
        self.btn.layer.masksToBounds = YES;
        self.btn.layer.borderColor = kButtonDefaultColor.CGColor;
        self.btn.layer.borderWidth = 1;
        
        self.titleLab = [UILabel createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        self.titleLab.numberOfLines = 2;
        self.titleLab.textAlignment = 1;
        [self.contentView addSubview:self.titleLab];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(60);
            make.right.equalTo(self.contentView.mas_right).offset(-60);
            make.top.equalTo(self.iconV.mas_bottom).offset(5);
            make.bottom.equalTo(self.btn.mas_top).offset(-5);
        }];
        
        
    }
    return self;
}

- (void)clickBtn{
    if (_clickBtnBlock) {
        _clickBtnBlock();
    }
}

- (void)setIsNetError:(BOOL)isNetError{
    _isNetError = isNetError;
    
    if (isNetError) {
        
        self.iconV.image = [UIImage imageNamed:@"icon_netError"];
        self.titleLab.text = ASLocalizedString(@"NetError");
        [self.btn setTitle:ASLocalizedString(@"Try Again") forState:UIControlStateNormal];
        [self.btn setTitle:ASLocalizedString(@"Try Again") forState:UIControlStateSelected];
        [self.btn setTitle:ASLocalizedString(@"Try Again") forState:UIControlStateHighlighted];
        
    }
    else {
        
        self.iconV.image = [UIImage imageNamed:@"icon_empty"];
        self.titleLab.text = ASLocalizedString(@"DataEmpty");
        [self.btn setTitle:ASLocalizedString(@"Go Apply") forState:UIControlStateNormal];
        [self.btn setTitle:ASLocalizedString(@"Go Apply") forState:UIControlStateSelected];
        [self.btn setTitle:ASLocalizedString(@"Go Apply") forState:UIControlStateHighlighted];
    }
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
